import Flutter
import UIKit

public class SwiftOpenWxScanPlugin: NSObject, FlutterPlugin {
  public static func register(with registrar: FlutterPluginRegistrar) {
    let channel = FlutterMethodChannel(name: "open_wx_scan", binaryMessenger: registrar.messenger())
    let instance = SwiftOpenWxScanPlugin()
    registrar.addMethodCallDelegate(instance, channel: channel)
  }

  public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
      if(call.method == "getPlatformVersion") {
          result("iOS " + UIDevice.current.systemVersion)
      } else if(call.method == "openWxScan") {
          let urlString = "weixin://scanqrcode"
          if let url = URL(string: urlString) {
              if #available(iOS 10, *) {
                  UIApplication.shared.open(url, options: [:],
                    completionHandler: {
                      (success) in
                    }
                  )
              } else {
                  UIApplication.shared.openURL(url)
              }
              result("Success")
          }
      }
  }
}
